dt = {}

while True:
    try:
        wd = input()
        if wd in dt:
            dt[wd] += 1
        else:
            dt[wd] = 1
        # dt[wd] = dt.get(wd, 0) + 1
    except:
        break

result = []

for x in dt.items():
    result.append(x)

result.sort(key=lambda x: (-x[1], x[0]))

for x in result:
    print(x[1], x[0])
